namespace FormInputProject.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class change2 : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.Records",
                c => new
                    {
                        RecordId = c.Int(nullable: false, identity: true),
                        PointId = c.Int(nullable: false),
                        OriginValue = c.Single(nullable: false),
                        CalculateValue = c.Single(nullable: false),
                        WriteTime = c.DateTime(nullable: false),
                        Modified = c.DateTime(nullable: false),
                        Creator_UserId = c.Int(),
                        ModifiedBy_UserId = c.Int(),
                    })
                .PrimaryKey(t => t.RecordId)
                .ForeignKey("dbo.Points", t => t.PointId, cascadeDelete: true)
                .ForeignKey("dbo.Users", t => t.Creator_UserId)
                .ForeignKey("dbo.Users", t => t.ModifiedBy_UserId)
                .Index(t => t.PointId)
                .Index(t => t.Creator_UserId)
                .Index(t => t.ModifiedBy_UserId);
            
            AddColumn("dbo.Points", "Formula", c => c.String());
            AddColumn("dbo.Points", "CalculatePoint", c => c.Boolean(nullable: false));
            AddColumn("dbo.Points", "Unit", c => c.String());
            AddColumn("dbo.Points", "Created", c => c.DateTime(nullable: false));
            AddColumn("dbo.Points", "Modified", c => c.DateTime(nullable: false));
            AddColumn("dbo.Points", "Creator_UserId", c => c.Int());
            AddColumn("dbo.Points", "ModifiedBy_UserId", c => c.Int());
            AddForeignKey("dbo.Points", "Creator_UserId", "dbo.Users", "UserId");
            AddForeignKey("dbo.Points", "ModifiedBy_UserId", "dbo.Users", "UserId");
            CreateIndex("dbo.Points", "Creator_UserId");
            CreateIndex("dbo.Points", "ModifiedBy_UserId");
            DropColumn("dbo.Points", "CreateDate");
            DropColumn("dbo.Points", "Creator");
        }
        
        public override void Down()
        {
            AddColumn("dbo.Points", "Creator", c => c.String());
            AddColumn("dbo.Points", "CreateDate", c => c.DateTime(nullable: false));
            DropIndex("dbo.Records", new[] { "ModifiedBy_UserId" });
            DropIndex("dbo.Records", new[] { "Creator_UserId" });
            DropIndex("dbo.Records", new[] { "PointId" });
            DropIndex("dbo.Points", new[] { "ModifiedBy_UserId" });
            DropIndex("dbo.Points", new[] { "Creator_UserId" });
            DropForeignKey("dbo.Records", "ModifiedBy_UserId", "dbo.Users");
            DropForeignKey("dbo.Records", "Creator_UserId", "dbo.Users");
            DropForeignKey("dbo.Records", "PointId", "dbo.Points");
            DropForeignKey("dbo.Points", "ModifiedBy_UserId", "dbo.Users");
            DropForeignKey("dbo.Points", "Creator_UserId", "dbo.Users");
            DropColumn("dbo.Points", "ModifiedBy_UserId");
            DropColumn("dbo.Points", "Creator_UserId");
            DropColumn("dbo.Points", "Modified");
            DropColumn("dbo.Points", "Created");
            DropColumn("dbo.Points", "Unit");
            DropColumn("dbo.Points", "CalculatePoint");
            DropColumn("dbo.Points", "Formula");
            DropTable("dbo.Records");
        }
    }
}
